package dk.itu.spct;

import java.io.BufferedInputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class TestingApp {
	public static void main (String args[]) throws Exception{
		InetAddress serverAddress = InetAddress.getByName("localhost");
		int serverPort = 12345;
		Socket socket = new Socket(serverAddress, serverPort);
		
		File myFile = new File ("C:\\Users\\Jesper\\workspace\\mt4j-desktop_bak\\examples\\images\\Jesper Sandberg.jpg");
	    byte [] mybytearray  = new byte [(int)myFile.length()];
	    FileInputStream fis = new FileInputStream(myFile);
	    BufferedInputStream bis = new BufferedInputStream(fis);
	    bis.read(mybytearray,0,mybytearray.length);
	    
	    OutputStream os = socket.getOutputStream();
	    DataOutputStream dos = new DataOutputStream(os);
	    
        dos.writeInt((int)myFile.length());
        dos.write(mybytearray,0,mybytearray.length);
        dos.flush();
        dos.close();
        
        System.out.println("Bytes: "+(int)myFile.length());
	}
}
